﻿@{
    ViewData["Title"] = "修改分类";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>修改分类</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>设备类型名称</label>
            <div class="layui-input-block">
                <input type="text" name="ItemTypeName" autocomplete="off" placeholder="请输入设备类型名称" lay-verify="required" class="layui-input" id="name">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">启用状态</label>
            <div class="layui-input-block">
                <input type="radio" name="EnableFlag" value="Y" title="是" id="Y">
                <input type="radio" name="EnableFlag" value="F" title="否" id="F">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>备注</label>
            <div class="layui-input-block">
                <input type="text" name="ItemTypeName" autocomplete="off" placeholder="请输入内容" lay-verify="required" class="layui-input" id="remark">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="demo3">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">取消</button>
        </div>
    </form>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        //JavaScript代码
        layui.use(['form'], function () {
            var form = layui.form;
            var layer = layui.layer;
            function getchildIframeData() {
                console.log(parent.machineTypeName)
                $("#name").val(parent.machineTypeName);//获取父页面的ItemTypeName值
                $("#remark").val(parent.remark);//获取父页面的OrderNum值
                
                if (parent.enableFlag == "Y") {
                    $("#Y").prop("checked", true);
                } else {
                    $("#F").prop("checked", true);
                }
                form.render("select");//重新渲染表单
                form.render();//重新渲染表单
            }
            getchildIframeData()
            // 修改事件
            form.on('submit(demo3)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field);
                var id = parent.id;
                var dto = {
                    Id: id,
                    MachineTypeCode: parent.machineTypeCode,
                    MachineTypeName: parent.machineTypeName,
                    EnableFlag: parent.enableFlag,
                    Remark: parent.remark,
                    CreateTime: parent.createTime,
                    CreateBy: parent.createBy,
                };
                // 此处可执行 Ajax 等操作
                $.get("/Li/UpdateMachineryType", dto, res => {
                    if (res) {
                        layer.msg('保存成功', {
                            icon: 1,
                            time: 2000
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                        });
                    }
                    else {
                        layer.msg('网络异常，请重试', {
                            icon: 1,
                            time: 1000
                        });
                    }
                });
                return false; // 阻止默认 form 跳转
            });
        });
    </script>
</body>
</html>
